Function.RegisterNamespace("System.Web.StorageStrategy");

System.Web.StorageStrategy.Redmond=function(){
    // Private Members
    var _id="System:Web:StorageStrategy:Redmond:{0}";
    var _key="localStorage";

    // ctor
    function Redmond(key){
        if(key){
            _key=key;
        }
        id=String.Format(_id,key);
    }
    Redmond.apply(this,arguments);
    
    // IStorageStrategy Methods
    this.Clear=function(name){
        var storage=ensureLocalStorage();
        storage.load(_key);
        storage.removeAttribute(name);
        storage.save(_key);
    };

    this.Get=function(name){
        var storage=ensureLocalStorage();
        storage.load(_key);
        return storage.getAttribute(name);
    };

    this.Set=function(name,value){
        var storage=ensureLocalStorage();
        storage.load(_key);
        storage.setAttribute(name,value);
        storage.save(_key);
    };

    // IStrategySpecification Members
    this.IsSatisfiedBy=function(candidate){
        return !!candidate.localStorage;
    };

    // Private Methods
    function ensureLocalStorage(){
        var storage=System.Web.Dom.GetElement(_id);
        if(!storage){
            System.Web.Dom.CreateElement(document.body,{id:_id,style:{behavior:"url(#default#userData)"}});
        }
        return storage;
    }

};

System.Web.StorageStrategy.Redmond.Implement(System.Web.Storage.IStorageStrategy,"System.Web.StorageStrategy.Redmond");
System.Web.StorageStrategy.Redmond.Implement(System.Script.Strategy.IStrategySpecification,'System.Web.StorageStrategy.Redmond');